package com.lagou.edu.spring.core.impl;

import com.lagou.edu.spring.exceptions.MySpringException;

import java.util.Arrays;
import java.util.List;

/**
 * 注解式配置容器
 *
 * @author 大犬
 * @date 2020/3/31
 */
public class AnnotationConfigApplicationContext extends AbstractApplicationContext {


    private BeanDefinitionParser beanDefinitionParser;

    public AnnotationConfigApplicationContext(Class configBeanClass) {
        beanDefinitionParser = new BeanDefinitionParser(this);
        beanDefinitionParser.parseConfig(configBeanClass);
    }

    public AnnotationConfigApplicationContext(String packageName) {
        this(Arrays.asList(packageName));
    }

    public AnnotationConfigApplicationContext(List<String> packageNames) {
        if (packageNames == null) {
            throw new MySpringException("scan package cannot be null");
        }
        beanDefinitionParser = new BeanDefinitionParser(this);
        packageNames.forEach(beanDefinitionParser::parsePackage);
    }

}
